package com.shopping_assistant.view.tabs;

import com.shopping_assistant.model.Person;
import com.shopping_assistant.model.PersonController;
import com.shopping_assistant.model.VisitCounter;
import com.shopping_assistant.view.ShopView;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class TopTenShopsTab extends ListActivity {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        ArrayAdapter<VisitCounter> arrayAdapter = new ArrayAdapter<VisitCounter>(this, android.R.layout.simple_list_item_1, PersonController.getInstance().getActiveUser().getShopsVisited());
        
        setListAdapter(arrayAdapter);
        
    }
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		
		VisitCounter selectedItem = (VisitCounter)l.getItemAtPosition(position);
		
		selectedItem.countVisit();
		
		Intent shopDetailsView = new Intent(TopTenShopsTab.this, ShopView.class);
		shopDetailsView.putExtra("latitude", selectedItem.getShop().getLatitude());
		shopDetailsView.putExtra("longitude", selectedItem.getShop().getLongitude());
		
		startActivity(shopDetailsView);
		
		super.onListItemClick(l, v, position, id);
	}
	
}
